package com.sumer.psychology.common.domain.model;

/**
 * 一般用户接口
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/11/14
 * Time: 10:34
 */
public abstract class User {
    private String identity;
    private String name;

    private Profile profile;

    public User() {
    }

    public User(String identity, String name) {
        this.identity = identity;
        this.name = name;
    }

    public User(String identity, String name, String userName, Integer gender, String phone, String qq, String email) {
        this(identity, name);
        this.profile = new Profile(userName, Gender.create(gender), phone, qq, email);
    }

    public static Class userClass(Integer role) {
        switch (role) {
            case 3:
                return Teacher.class;
            case 4:
                return Agent.class;
            case 5:
                return Student.class;
            default:
                return Student.class;
        }
    }

    public abstract Role role();

    public String identity() {
        return identity;
    }

    public String name() {
        return name;
    }

    public Profile profile() {
        return profile;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (identity != null ? !identity.equals(user.identity) : user.identity != null) return false;
        if (name != null ? !name.equals(user.name) : user.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = identity != null ? identity.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "User{" +
                "identity='" + identity + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
